#include <string>
#include <map>
#include <vector>
using namespace std;

typedef struct memorySegment{
  string segName;
  void * virtualAddress;
  int fd;
  int size;
  int dirty;
} mSeg;

struct rvm_info{
  string backingStore;
  FILE * log;
  map<string, mSeg*> mSegs;
};
typedef struct rvm_info* rvm_t;

typedef struct transItem{
  mSeg * transmSeg;
  int offset;
  int size;
} transactionItem;

struct transactionInfo{
  map<void *, mSeg *> mSegs;
  vector<transactionItem*> transactions;
  rvm_t rvm;
};
typedef struct transactionInfo* trans_t;

typedef struct logSegment{
  int size;
  int offset;
  string segName;
  int commitflag;
  int initflag;
  //map<string, mSeg*> mlogSegs;
  char *modifieddata;
} mlogSeg;



//rvm ops

extern "C" rvm_t rvm_init(const char * directory);

extern "C" void * rvm_map(rvm_t rvm, const char * segname, int size_to_create);

extern "C" void rvm_unmap(rvm_t rvm, void * segbase);

extern "C" void rvm_destroy(rvm_t rvm, const char * segname);

//transactional ops

extern "C" trans_t rvm_begin_trans(rvm_t rvm, int numsegs, void ** segbases);

extern "C" void rvm_about_to_modify(trans_t tid, void * segbase, int offset, int size);

extern "C" void rvm_commit_trans(trans_t tid);

extern "C" void rvm_abort_trans(trans_t tid);

//log control

extern "C" void rvm_truncate_log(rvm_t rvm);

extern "C" void read_log(rvm_t rvm);

//library output

extern "C" void rvm_verbose(int enable_flag);
